<template>
  <div class="grade-appeal">
    <el-card>
      <template #header>
        <div class="card-header">
          <span>成绩申诉</span>
        </div>
      </template>

      <el-form :model="appealForm" label-width="120px">
        <el-form-item label="考试名称">
          <el-input v-model="appealForm.examName" disabled />
        </el-form-item>
        
        <el-form-item label="当前分数">
          <el-input v-model="appealForm.currentScore" disabled />
        </el-form-item>
        
        <el-form-item label="申诉理由">
          <el-input
            v-model="appealForm.reason"
            type="textarea"
            rows="4"
            placeholder="请详细描述申诉理由"
          />
        </el-form-item>
        
        <el-form-item label="附件">
          <el-upload
            action="#"
            :auto-upload="false"
            :on-change="handleFileChange"
          >
            <el-button type="primary">选择文件</el-button>
            <template #tip>
              <div class="el-upload__tip">
                可上传图片或PDF文件作为证明材料
              </div>
            </template>
          </el-upload>
        </el-form-item>
        
        <el-form-item>
          <el-button type="primary" @click="submitAppeal">
            提交申诉
          </el-button>
          <el-button @click="goBack">返回</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'

const route = useRoute()
const router = useRouter()

const appealForm = ref({
  examName: '期中考试',
  currentScore: 85,
  reason: '',
  files: []
})

onMounted(() => {
  // 获取考试ID
  const examId = route.query.examId
  // 这里可以根据examId获取考试信息
})

// 处理文件变化
const handleFileChange = (file) => {
  appealForm.value.files.push(file)
}

// 提交申诉
const submitAppeal = () => {
  if (!appealForm.value.reason) {
    ElMessage.warning('请填写申诉理由')
    return
  }
  
  // 这里添加提交申诉的逻辑
  ElMessage.success('申诉已提交')
  router.push('/student/results')
}

// 返回
const goBack = () => {
  router.back()
}
</script>

<style scoped>
.grade-appeal {
  padding: 20px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
</style> 